package stu.officedrunker.applications.common.validation.constraints.impl;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import stu.officedrunker.applications.common.validation.constraints.CodeIntValue;

/**
 * 정수형 코드의 validator.
 * @author 서성수
 */
public class CodeIntValueValidator implements ConstraintValidator<CodeIntValue, Integer> {

	private int[] codeValues;

	//@Override
	public void initialize(CodeIntValue constraint) {
		this.codeValues = constraint.value();
	}

	//@Override
	public boolean isValid(Integer value, ConstraintValidatorContext context) {
		if (value == null)
			return true;
		for (int codeValue : codeValues) {
			if (codeValue == value)
				return true;
		}
		return false;
	}

}
